//
//  PYCGroupTableController.m
//  PinyinContacts
//
//  Created by Xiaoping Zhang on 2/15/10.
//  Copyright 2010 Filters, Inc. All rights reserved.
//

#import "PYCGroupTableController.h"
#import <AddressBook/ABGroup.h>
#import <AddressBook/ABAddressBook.h>

@interface PYCGroupTableController ()

-(NSArray *) contactGroups;

@end

@implementation PYCGroupTableController

- (void)dealloc
{
	[super dealloc];
	
	[contactGroups release];
}

- (NSArray *)contactGroups
{
	if (contactGroups)
		return contactGroups;
	
	contactGroups = [[ABAddressBook sharedAddressBook] groups];
	return [contactGroups retain];
}

- (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(int)rowIndex
{
	ABGroup *group = [[self contactGroups] objectAtIndex:rowIndex];
	
	return [group valueForProperty:kABGroupNameProperty];
}

- (int)numberOfRowsInTableView:(NSTableView *)aTableView
{
    return [[self contactGroups] count];
}

- (ABGroup *) groupAtIndex:(NSUInteger)index
{
	return [[self contactGroups] objectAtIndex:index];
}

- (NSUInteger) countOfGroups
{
	return [[self contactGroups] count];
}

@end
